#include <cstdio>
#include <queue> 
using namespace std;
const int maxn=10010;
struct node{
	int v;
	bool operator <(const struct node x)const{
		return v>x.v;
	}
}cur;
priority_queue<struct node> pq;
int main(){
	int n,sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&cur.v);
		pq.push(cur);
	}
	for(int i=1;i<n;i++){
		cur=pq.top(); pq.pop();
		cur.v+=pq.top().v; pq.pop();
		sum+=cur.v; pq.push(cur); 
	}
	printf("%d\n",sum);
	return 0;
}

